package guda.shop.cms.manager.impl;

import guda.shop.cms.dao.ShopAdminDao;
import guda.shop.cms.entity.ShopAdmin;
import guda.shop.cms.manager.ShopAdminMng;
import guda.shop.common.hibernate3.Updater;
import guda.shop.common.page.Pagination;
import guda.shop.core.entity.Admin;
import guda.shop.core.entity.Website;
import guda.shop.core.manager.AdminMng;
import guda.shop.core.manager.UserMng;
import guda.shop.core.manager.WebsiteMng;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class ShopAdminMngImpl
        implements ShopAdminMng {
    private UserMng userMng;
    private WebsiteMng websiteMng;
    private AdminMng adminMng;
    private ShopAdminDao shopAdminDao;

    public ShopAdmin getByUserId(Long paramLong1, Long paramLong2) {
        Admin localAdmin = this.adminMng.getByUserId(paramLong1, paramLong2);
        if (localAdmin == null)
            return null;
        return findById(localAdmin.getId());
    }

    public ShopAdmin register(String paramString1, String paramString2, Boolean paramBoolean, String paramString3, String paramString4, boolean paramBoolean1, Long paramLong, ShopAdmin paramShopAdmin) {
        Website localWebsite = this.websiteMng.findById(paramLong);
        Admin localAdmin = this.adminMng.register(paramString1, paramString2, paramString3, paramString4, Boolean.valueOf(paramBoolean1), localWebsite, paramBoolean);
        paramShopAdmin.setAdmin(localAdmin);
        paramShopAdmin.setWebsite(localWebsite);
        return save(paramShopAdmin);
    }

    @Transactional(readOnly = true)
    public Pagination getPage(Long paramLong, int paramInt1, int paramInt2) {
        Pagination localPagination = this.shopAdminDao.getPage(paramLong, paramInt1, paramInt2);
        return localPagination;
    }

    @Transactional(readOnly = true)
    public ShopAdmin findById(Long paramLong) {
        ShopAdmin localShopAdmin = this.shopAdminDao.findById(paramLong);
        return localShopAdmin;
    }

    public ShopAdmin save(ShopAdmin paramShopAdmin) {
        this.shopAdminDao.save(paramShopAdmin);
        return paramShopAdmin;
    }

    public ShopAdmin update(ShopAdmin paramShopAdmin, String paramString1, Boolean paramBoolean1, String paramString2, Boolean paramBoolean2) {
        ShopAdmin localShopAdmin = findById(paramShopAdmin.getId());
        Admin localAdmin = localShopAdmin.getAdmin();
        this.userMng.updateUser(localAdmin.getUser().getId(), paramString1, paramString2);
        if (paramBoolean1 != null)
            localAdmin.setDisabled(paramBoolean1);
        localAdmin.setViewonlyAdmin(paramBoolean2);
        Updater localUpdater = new Updater(paramShopAdmin);
        localShopAdmin = this.shopAdminDao.updateByUpdater(localUpdater);
        return localShopAdmin;
    }

    public ShopAdmin deleteById(Long paramLong) {
        ShopAdmin localShopAdmin = this.shopAdminDao.deleteById(paramLong);
        return localShopAdmin;
    }

    public ShopAdmin[] deleteByIds(Long[] paramArrayOfLong) {
        ShopAdmin[] arrayOfShopAdmin = new ShopAdmin[paramArrayOfLong.length];
        int i = 0;
        int j = paramArrayOfLong.length;
        while (i < j) {
            arrayOfShopAdmin[i] = deleteById(paramArrayOfLong[i]);
            i++;
        }
        return arrayOfShopAdmin;
    }

    @Autowired
    public void setDao(ShopAdminDao paramShopAdminDao) {
        this.shopAdminDao = paramShopAdminDao;
    }

    @Autowired
    public void setAdminMng(AdminMng paramAdminMng) {
        this.adminMng = paramAdminMng;
    }

    @Autowired
    public void setWebsiteMng(WebsiteMng paramWebsiteMng) {
        this.websiteMng = paramWebsiteMng;
    }

    @Autowired
    public void setUserMng(UserMng paramUserMng) {
        this.userMng = paramUserMng;
    }
}

